package com.example.administrator.fastdream.date.presenter;

import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;

import com.example.administrator.fastdream.date.bean.LookAllRecordBean;
import com.example.administrator.fastdream.date.http.JsonCallback;
import com.example.administrator.fastdream.date.utils.MyUrl;
import com.example.administrator.fastdream.view.activity.LoginActivity;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpParams;
import com.lzy.okgo.model.Response;

public class LookAllRecordPresenter {
    private Activity mActivity;
    private LookAllRecordCallBack callBack;

    public LookAllRecordPresenter(Activity activity, LookAllRecordCallBack callBack) {
        this.mActivity = activity;
        this.callBack = callBack;
    }

    public void lookAllRecord(int page) {
        HttpParams params = new HttpParams();
        params.put("page", page);
        params.put("page_size", 10);
        OkGo.<LookAllRecordBean>post(MyUrl.BASEURL + "Home/dream_story")
                .tag(this)
                .params(params)
                .execute(new JsonCallback<LookAllRecordBean>(LookAllRecordBean.class) {
                    @Override
                    public void onSuccess(Response<LookAllRecordBean> response) {
                        if (response.body() == null) {
                            return;
                        }
                        String status = response.body().getStatus();
                        if (status.equals("1")) {
                            callBack.lookAllRecord(response.body());
                        } else if (status.equals("2")) {
                            Toast.makeText(mActivity, response.body().getMessage(), Toast.LENGTH_SHORT).show();
                        } else {
                            mActivity.startActivity(new Intent(mActivity, LoginActivity.class));
                        }
                    }
                });
    }

    public interface LookAllRecordCallBack {
        void lookAllRecord(LookAllRecordBean lookAllRecordBean);
    }
}
